<?php
$this->pageTitle=Yii::app()->name . ' - Поиск рассрочки';
$this->breadcrumbs=array(
	'Поиск рассрочки',
);
?>

<?php $this->renderPartial('//menus/_operator_menu',array('active'=>'credits'))?>
<fieldset>
	<legend>Поиск рассрочки</legend>
	<div class="row">
		<div class="span12">
			<?php if(count(Yii::app()->searchHistory->getCreditsHistory())):?>
			<div class="well">
				<p style="text-decoration: underline;">Истроия поиска:</p>
				<div>
					<?php foreach(Yii::app()->searchHistory->getCreditsHistory() as $item):?>
					<?=CHtml::link('<span class="label">Договор №'.$item.'</span>',Yii::app()->createUrl('credits/view',array('id'=>$item)));?>
					<?php endforeach;?>
				</div>
			</div>
			<?php endif;?>

			<div class="well">
				<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm', array(
					'id'=>'search-credit-form',
					'type'=>'inline',
					'htmlOptions'=>array('style'=>'margin: 0;')
				)); ?>

				<?php echo $form->textFieldRow($SearchForm,'credit_id',array('class'=>'input-block-level')); ?>

				<div style="margin-top: 10px;">
					<?php $this->widget('bootstrap.widgets.TbButton', array(
						'buttonType'=>'submit',
						'type'=>'success',
						'loadingText'=>'Идет поиск...',
						'label'=>'Найти',
						'htmlOptions'=>array('id'=>'search-button','style'=>'width:140px;')
					)); ?>
				</div>

				<?php $this->endWidget(); ?>
			</div>

			<?php if($dataProvider !== null):?>
			<div>
				<?php $this->widget('bootstrap.widgets.TbGridView', array(
					'type'=>'striped condensed',
					'dataProvider'=>$dataProvider,
					'enablePagination'=>true,
					'template'=>"{items}{pager}",
					'emptyText'=>'Договор рассрочки не найден',
					'showTableOnEmpty'=>false,
					'enableSorting'=>false,
					'columns'=>array(
						'id',
						array(
							'name'=>'client.surname',
							'header'=>'ФИО',
							'value'=>'CHtml::link($data->client->surname." ".$data->client->name." ".$data->client->patronymic,Yii::app()->createUrl("clients/view",array("id"=>$data->client->id)))',
							'type'=>'raw'
						),
						'sum',
						array(
							'name'=>'repaymentsSum',
							'header'=>'Выплачено',
							'value'=>'$data->repaymentsSum?$data->repaymentsSum:"-"'
						),
						array(
							'name'=>'paySum',
							'header'=>'Остаток',
							'value'=>'$data->repaymentsSum?$data->sum - $data->repaymentsSum:"-"'
						),
						array(
							'name'=>'status',
							'value'=>'Credits::getStatusName($data->status)',
							'type'=>'raw'
						),
						array(
							'class'=>'bootstrap.widgets.TbButtonColumn',
							'template'=>'{show}',
							'htmlOptions'=>array('style'=>'width: 120px; text-align: right;'),
							'buttons'=>array(
								'show' => array(
									'label'=>'Просмотр',
									'url'=>'Yii::app()->createUrl("credits/view",array("id"=>$data->id))',
									'options'=>array('title'=>'Просмотр данных','class'=>'btn btn-small btn-primary'),
								)
							)
						),
					),
				)); ?>
			</div>
			<?php endif;?>
		</div>
	</div>
</fieldset>

<script type="text/javascript">
	$(document).ready(function(){
		$('#search-button').click(function() {
			$(this).button('loading'); // call the loading function
		});
	});
</script>